Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java Mail Interview Questions and Answers

Question: Explain the use of MIME within message makeup.
Answer: Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(args[0])};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Hello");
msg.setSentDate(new Date());
msg.setText("Mail Message");

This section creates the actual message object and fills in the to, from, subject, date and content. There are also options to set the reply to, content and content type, and other header information. Since this is a MIME - Multipurpose Internet Mail Extensions - message, it need not be plain text.

A DataHandler can be set using setDataHandler() in MimeMessage to handle nontext parts. This is a simple one-part text message, the setText() can be used.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook